package org.example.agent.control;

import org.example.agent.task.*;
import org.example.util.ThreadUtil;
import org.example.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/agent")
public class DeployController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DeployController.class);

    @GetMapping("/checkhealth")
    public Result<String> checkHealth(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent 健康检查。");
        ThreadUtil.submitTask(new CheckHealthTask(params));
        return Result.OK();
    }

    @GetMapping("/diskcheck")
    public Result<String> diskcheck(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent 磁盘检查。");
        ThreadUtil.submitTask(new DiskCheckTask(params));
        return Result.OK();
    }

    @GetMapping("/filecopy")
    public Result<String> fileCopy(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent 文件复制。");
        ThreadUtil.submitTask(new FileCopyTask(params));
        return Result.OK();
    }

    @GetMapping("/fileunzip")
    public Result<String> fileUnzip(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent 文件解压。");
        ThreadUtil.submitTask(new FileUnzipTask(params));
        return Result.OK();
    }

    @GetMapping("/fileconfig")
    public Result<String> fileConfig(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent 文件配置。");
        ThreadUtil.submitTask(new FileConfigTask(params));
        return Result.OK();
    }

    @GetMapping("/envconfig")
    public Result<String> executeScript(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent 环境配置。");
        ThreadUtil.submitTask(new EnvConfigTask(params));
        return Result.OK();
    }

    @GetMapping("/unInstallScript")
    public Result<String> unInstallScript(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent 执行卸载脚本。");
        ThreadUtil.submitTask(new UninstallTask(params));
        return Result.OK();
    }

    @GetMapping("/cleanDir")
    public Result<String> cleanDir(@RequestParam(name = "params", required = true) String params) {
        LOGGER.info("agent清理目录。");
        ThreadUtil.submitTask(new CleanTask(params));
        return Result.OK();
    }

}
